using System;
using System.Threading;

namespace SecuBat.AttackPlugin
{
	/// <summary>
	/// Summary description for AnalysisBase.
	/// </summary>
	public class AnalysisBase : IAnalysis
	{
		private int _id;
		private int _attackId;
		private int _pluginId;
		private String _responseHtml;
		private int _responseCode;
		private int _analysisResult;
		private String _analysisText;
		private ICommonData _data;

		public string ResponseHtml
		{
			get { return _responseHtml; }
			set { _responseHtml = value; }
		}

		public int ResponseCode
		{
			get { return _responseCode; }
			set { _responseCode = value; }
		}

		public int AnalysisResult
		{
			get { return _analysisResult; }
			set { _analysisResult = value; }
		}

		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		public int PluginId
		{
			get { return _pluginId; }
			set { _pluginId = value; }
		}

		public int AttackId
		{
			get { return _attackId; }
			set { _attackId = value; }
		}

		public string AnalysisText
		{
			get { return _analysisText; }
			set { _analysisText = value; }
		}

		public ICommonData Data
		{
			get { return _data; }
			set { _data = value; }
		}

		public AnalysisBase(ICommonData data)
		{
			PluginId = -1;
			AnalysisResult = 0;
			Id = -1;
			AttackId = -1;
			_data = data;
		}

		public virtual void Execute(IAttack attackToAnalyze)
		{
			this.ResponseCode = attackToAnalyze.ResponseCode;
			this.ResponseHtml = attackToAnalyze.ResponseHtml;
			this.AttackId = attackToAnalyze.Id;
			this.PluginId = attackToAnalyze.PluginId;

			this.InitializeAnalysis();
			Thread.Sleep(1);
			this.DoAnalysis();
			Thread.Sleep(1);
			this.Register();
			Thread.Sleep(1);
		}

		public virtual void InitializeAnalysis()
		{
		}

		public virtual void DoAnalysis()
		{
		}

		public virtual void Register()
		{
			Id = AttackDbManager.NewAnalysis(AttackId, PluginId, AnalysisResult, AnalysisText);
		}
	}
}
